<template>
  <van-icon
  color="#777"
  :name="value?'star':'star-o'"
  :class="{collected:value}"
  @click="onClick"
  />
</template>

<script>

import { addCollect, deleteCollect } from '@/api/article'
export default {
  name: 'CollectArticle',
  props: {
    value: {
      type: Boolean,
      required: true
    },
    articleId: {
      type: [Number, String, Object],
      required: true
    }
  },
  components: {},
  data () {
    return {
      loading: false
    }
  },
  created () {},
  mounted () {},
  methods: {
    async onClick () {
      if (this.loading) return
      this.loading = true

      if (this.value) {
        //   取消收藏
        await deleteCollect(this.articleId)
      } else {
        //   收藏
        await addCollect(this.articleId)
      }
      this.$emit('input', !this.value)
      this.$toast(!this.value ? '收藏成功' : '取消收藏')
      this.loading = false
    }
  },
  watch: {},
  computed: {}
}
</script>

<style lang="less" scoped>
.collected{
    color: #ffa500 !important;
}
</style>
